#pragma once

#include "controller.h"
#include <vector>
#include <map>

enum KeyDef
{
	ButtonUNDEFINED = -1,
	ButtonUP = 0,
	ButtonDOWN,
	ButtonLEFT,
	ButtonRIGHT,
	ButtonA,
	ButtonB,
	ButtonC,
	ButtonD,
	KeyNum,
};

struct OneFrameInput
{
	OneFrameInput()
	{
		memset(keystate,0,sizeof(keystate));
		timestamp = 0;
	}
	const OneFrameInput& operator=(const OneFrameInput& val)
	{
		memcpy( keystate, val.keystate, sizeof(keystate));
		timestamp = val.timestamp;
		return *this;
	}
	bool operator==(const OneFrameInput& val)
	{
		for( int i=0;i<KeyNum;i++ )
		{
			if( keystate[i] != val.keystate[i] )
				return false;
		}
		return true;
	}
	bool operator!=(const OneFrameInput& val)
	{
		return !(*this == val);
	}
	char keystate[KeyNum];
	unsigned int timestamp;
};
typedef std::vector<OneFrameInput> KeySequence;
struct KeyActionDef
{
	
	KeySequence mKeySequence;
	std::string actionname;
};

typedef std::vector<KeyActionDef> KeyActionDefVec;
class PlayController:public Controller
{
public:
	PlayController();
	virtual ~PlayController();
	virtual void Update();
	virtual void SetEntity( Entity *e );
	void ParseActions();
	int KeyStringToEnum( std::string str );
	bool MatchKeySequence( KeySequence &defined );
	
	bool IsKeyPressed( int key );
	bool IsKeyPressing( int key );
	OneFrameInput mCurframe;
	OneFrameInput mLastframe;
	int mKeyMapping[KeyNum];
	KeyActionDefVec mKeyActionDefs;
	KeySequence mInputRecord;
};